package com.minelx.table.core.series.index;

import java.util.stream.LongStream;

public class RangeIndexes implements Indexes {
	private final long from;

	private final long to;

	RangeIndexes(long from, long to) {
		this.from = from;
		this.to = to;
	}

	@Override
	public long at(long index) {
		if (index >= from && index < to) {
			return from + index;
		}
		throw new ArrayIndexOutOfBoundsException("out of indexes range: " + index + ", range: " + from + " to " + to);
	}

	@Override
	public long len() {
		return to - from;
	}

	@Override
	public LongStream stream() {
		return LongStream.range(from, to);
	}
}
